import Vue from "vue";
import VueRouter from "vue-router";

//解决连续点击同个路由出bug
const VueRouterPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(to) {
  return VueRouterPush.call(this, to).catch(err => err)
}

Vue.use(VueRouter);

const routes = [
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/Login'),
    meta: {
      title: '登录',
      nocheck: true //不用路由守卫：谁都能看
    }
  },
  {
    path: '/',
    redirect: '/login'
  },
  {
    path: '/home',
    name: 'home',
    component: () => import('../views/Home'),
    redirect: '/home/user',
    meta: {
      title: '主页'
    },
    children: [
      {
        path: 'user',
        name: 'user',
        component: () => import('../views/User'),
        meta: {
          title: '用户管理'
        }
      },
      {
        path: 'goods',
        name: 'goods',
        component: () => import('../views/Goods'),
        meta: {
          title: '商品管理'
        }
      },
      {
        path: 'order',
        name: 'order',
        component: () => import('../views/Order'),
        meta: {
          title: '订单管理'
        }
      },
      {
        path: 'discuss',
        name: 'discuss',
        component: () => import('../views/Discuss'),
        meta: {
          title: '评论管理'
        }
      },
    ]
  },
];



const router = new VueRouter({
  routes


});

// //全局路由钩子
// router.beforeEach(function (to, from, next) {
//   console.log(to, "to");
//   console.log(from, "from");
//   window.console.log("进入全局 beforeEach钩子了")
//   next();
// })

export default router;
